const app = getApp()
import util from '../../../utils/util.js'
import api from '../../../config/api.js'

Page({
  data: {
    info: [],
  },
  submit:function(e){
    let url = e.currentTarget.dataset.name.url;
    console.log(url);
    wx.navigateTo({
      url: '../dailydetail/dailydetail?url=' + url
    })
  },
  onReachBottom: function () {
    let that = this;
    requestData(that, mCurrentPage + 1);
  },
  onLoad: function () {
    let that = this;
    requestData(that, mCurrentPage + 1);
  }
})
let mCurrentPage = 44;
/**
 * 请求数据
 * @param that Page的对象，用来setData更新数据
 * @param targetPage 请求的目标页码
 */
function requestData(that, targetPage) {
  wx.showToast({
    title: '加载中',
    icon: 'loading'
  });
  util.request(api.zhihuList + targetPage).then(function (res) {
    let result = res.results;
    for (let item of result){
      item.published_at = item.published_at.replace('T', ' ').substr(0, 19);
    }
    let concat = that.data.info.concat(result);
    that.setData({
      info: concat
    });
    mCurrentPage ++;
    wx.hideToast();
  });
}

